package com.ccit.controller;

import com.ccit.domain.Location;
import com.ccit.service.LocationService;
import com.ccit.utils.Code;
import com.ccit.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/location")
@CrossOrigin(origins = "http://localhost:8080")
@Api(description = "位置管理")
public class LocationController {
    @Autowired
    private LocationService locationService;

    @GetMapping("/{location}")
    @ApiOperation(value = "根据地址获取经纬度")
    public Result getByLocation(@PathVariable String location) {
        Location result = locationService.getByLocation(location);
        Integer code = result != null ? Code.GET_OK : Code.GET_ERR;
        String msg = result != null ? "" : "数据查询失败，请重试！";
        return new Result(code,result,msg);
    }
}
